﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._03_AbstractFactory
{
    /// <summary>
    /// 支付处理器
    /// </summary>
    public class MyPaymentProcessor
    {
        private readonly IPaymentFactory _factory;

        public MyPaymentProcessor(IPaymentFactory factory)
        {
            _factory = factory;
        }

        public void ProcessOrder(decimal amount)
        {
            var validator = _factory.CreateValidator();
            if (validator.ValidatePayment())
            {
                var payment = _factory.CreatePayment();
                payment.Pay(amount);
                Console.WriteLine("支付处理完成");
            }
            else
            {
                Console.WriteLine("支付验证失败");
            }
        }
    }
}
